package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Test {
    public static void main(String[] args) {
        Connection con =null;
        PreparedStatement ps=null;
        try {
            //加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接
            con= DriverManager.getConnection("jdbc:mysql:///db2","root","myroot");

            //定义Sql
            String sql="delete from account where id = ?";

            ps = con.prepareStatement(sql);
            ps.setLong(1,12);

            int execute = ps.executeUpdate();
            System.out.println(execute);

        } catch ( ClassNotFoundException e ) {
            e.printStackTrace();
        } catch ( SQLException e ) {
            e.printStackTrace();

        }finally {
            if (ps!=null){
                try {
                    ps.close();
                } catch ( SQLException e ) {
                    e.printStackTrace();
                }
            };
        }

    }
}
